<?php
namespace App\Models;

use App\Models\Simple\CSVModel;
class Places extends CSVModel
{
    protected $origin = WRITEPATH . 'data/placesData.csv';

    protected $keyField = 'id';
    protected $validationRules = [
        'id' => 'required|integer|greater_than[0]', 
        'name' => 'required|string|max_length[50]', 
        'description' => 'required|string', 
        'link' => 'required|valid_url', 
        'image' => 'required|string|max_length[100]' 
    ];
    public function findLikeName(string $keyword)
    {
        $allData = $this->findAll(); 
        $matched = [];
        foreach ($allData as $item) {

            if (stripos($item['name'], $keyword) !== false) {
                $matched[] = $item;
            }
        }
        return $matched;
    }
}